bitkeeper revision 1.1108.30.3 (4107c922o_Bx20-5N8PsVBcjjHYmQA)
authortw275@labyrinth.cl.cam.ac.uk <tw275@labyrinth.cl.cam.ac.uk>
Wed, 28 Jul 2004 15:41:22 +0000 (15:41 +0000)
committertw275@labyrinth.cl.cam.ac.uk <tw275@labyrinth.cl.cam.ac.uk>
Wed, 28 Jul 2004 15:41:22 +0000 (15:41 +0000)
More work on wizard

.rootkeys
tools/python/xen/sv/CreateDomain.py
tools/python/xen/sv/Wizard.py
tools/python/xen/sv/util.py
tools/sv/Makefile
tools/sv/images/finish.png [new file with mode: 0644]

index be5ccf20d1999a2a5bc88abcf306c1082e57c5b1..5853abec5a90d151a0e3a1e4ad5403856ec86161 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 40cf2937Z8WCNOnO2FcWdubvEAF9QQ tools/python/xen/xm/shutdown.py
 40fcefb2K1xqVVT4D-p7nL2GzS4scg tools/sv/Main.rpy
 40ffbcb66Dj5F-1kCK9BcgSqCWkt1w tools/sv/Makefile
+4107c921_OR9NTSv2dKFiLCXxrXoxA tools/sv/images/finish.png
 40fcefb3wXQMsl9WkgQAVtdrupm4sw tools/sv/images/left-end-highlight.jpg
 40fcefb3K6ESt5sQhD9aCQRscQIlXQ tools/sv/images/left-end-no-highlight.jpg
 40fcefb3BUT98zPzW8kAFKuxGdh4XA tools/sv/images/middle-highlight.jpg
index 56ea043db85695f52e9f68b4d37464b1fc6c9ae5..62123871bd032ab3e1be8c1ea0494fc115f11906 100644 (file)
@@ -1,46 +1,70 @@
-from xen.sv.Wizard import Wizard, Sheet
+from xen.sv.Wizard import *
+from xen.sv.util import *
 
 class CreateDomain( Wizard ):
     def __init__( self, urlWriter ):
        
-       sheets = { 0: CreatePage0,
-                  1: CreatePage1,
-                  2: CreatePage2,
-                   3: CreatePage3 }
+       sheets = [ CreatePage0,
+                  CreatePage1,
+                  CreatePage2,
+                   CreatePage3,
+                   CreatePage4,
+                   CreateFinish ]
     
        Wizard.__init__( self, urlWriter, "Create Domain Wizard", sheets )
        
 class CreatePage0( Sheet ):
 
     def __init__( self, urlWriter ):
-    
-       feilds = [( 'name', 'VM Name:'),
-                  ( 'memory', 'RAM (Mb):' )]
-    
-        Sheet.__init__( self, urlWriter, feilds, "Create New Domain", 0 )
-                
+        Sheet.__init__( self, urlWriter, "General", 0 )
+        self.addControl( InputControl( 'vm_name', 'VM Name', 'VM Name:' ) )
+        self.addControl( InputControl( 'memory', '64', 'Memory (Mb):' ) )
+                        
 class CreatePage1( Sheet ):
 
     def __init__( self, urlWriter ):
-    
-       feilds = [( 'kernel_type', 'Kernel Type:'),
-                  ( 'kernel_location', 'Kernel location:')]
-        
-        Sheet.__init__( self, urlWriter, feilds, "Setup Kernel Image", 1 )
-        
+        Sheet.__init__( self, urlWriter, "Setup Kernel Image", 1 )
+        self.addControl( InputControl( 'kernel_image', '/boot/vmlinuz-2.4.26-xenU', 'Kernel Image:' ) )
+        self.addControl( InputControl( 'kernel_params', '', 'Kernel Command Line Parame:' ) )
+
 class CreatePage2( Sheet ):
 
     def __init__( self, urlWriter ):
-    
-       feilds = [( 'vbd_dom0', 'Location of vbd:'),
-                 ( 'vbd_dom0', 'Vitualised location:')]    
-   
-        Sheet.__init__( self, urlWriter, feilds, "Setup Virtual Block Devices", 2 )
-                
+       Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 2 )
+        self.addControl( InputControl( 'num_vbds', '1', 'Number of VBDs:' ) )
+
 class CreatePage3( Sheet ):
 
     def __init__( self, urlWriter ):
-    
-       feilds = [( 'vifs', 'Number of Vifs:')]
+        Sheet.__init__( self, urlWriter, "Setup Virtual Block Device", 3 )
+        
+    def write_BODY( self, request ):
+       previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
+        num_vbds = previous_values.get( 'num_vbds' )
+        
+        for i in range( int( num_vbds ) ):
+            self.addControl( InputControl( 'vbd%s_dom0' % i, '/dev/sda%i' % i, 'Device %s name:' % i  ) )
+            self.addControl( InputControl( 'vbd%s_domU' % i, '/dev/sda%i' % i, 'Virtualized device %s:' % i ) )
+            
+        self.addControl( InputControl( 'root_dev', '/dev/sda1', 'Root device (in VM):' ) )
+        
+        Sheet.write_BODY( self, request )
+                
+class CreatePage4( Sheet ):
+
+    def __init__( self, urlWriter ):        
+        Sheet.__init__( self, urlWriter, "Network settings", 4 )  
+        self.addControl( InputControl( 'hostname', 'hostname', 'VM Hostname:' ) )
+        self.addControl( InputControl( 'ip_addr', '1.2.3.4', 'VM IP Address:' ) )
+        self.addControl( InputControl( 'ip_subnet', '255.255.255.0', 'VM Subnet Mask:' ) ) 
+        self.addControl( InputControl( 'ip_gateway', '1.2.3.4', 'VM Gateway:' ) )           
+         
+class CreateFinish( Sheet ):
+
+    def __init__( self, urlWriter ):
+        Sheet.__init__( self, urlWriter, "All Done", 5 )
         
-        Sheet.__init__( self, urlWriter, feilds, "Create New Domain - 4", 3 )       
+    def write_BODY( self, request ):
+       request.write( "<pre>%s</pre>" % sxp2prettystring( string2sxp( self.passback ) ) )
+        request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
+        request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
index b9436d0ba163e7ebb9eaa7f6c9fe3723f86bceb2..d0b7a77177d45de4e40b52f2246feedf1a6ea2c3 100755 (executable)
@@ -32,16 +32,21 @@ class Wizard( HTMLBase ):
         if op == 'next':
             currSheet += 1
         elif op == 'prev':
-            currSheet -= 1    
+             currSheet -= 1
+             
+        sheet = self.sheets[ currSheet ]( self.urlWriter )    
             
-        self.sheets[ currSheet ]( self.urlWriter ).write_BODY( request )
+        sheet.parseForm( request )
+        sheet.write_BODY( request )
         
         request.write( "</td></tr><tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr>" )
         request.write( "<td width='80%'></td><td width='20%' align='center'><p align='center'>" )
        if currSheet > 0:
-                       request.write( "<img src='images/previous.png' onclick='doOp( \"prev\" )' onmouseover='update( \"wizText\", \"Previous\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>&nbsp;" )
-        if currSheet < ( len( self.sheets ) - 1 ):        
-               request.write( "<img src='images/next.png' onclick='doOp( \"next\" )' onmouseover='update( \"wizText\", \"Next\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>" )
+                   request.write( "<img src='images/previous.png' onclick='doOp( \"prev\" )' onmouseover='update( \"wizText\", \"Previous\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>&nbsp;" )
+        if currSheet < ( len( self.sheets ) - 2 ):        
+            request.write( "<img src='images/next.png' onclick='doOp( \"next\" )' onmouseover='update( \"wizText\", \"Next\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>" )
+        elif currSheet == ( len( self.sheets ) - 2 ):
+            request.write( "<img src='images/finish.png' onclick='doOp( \"next\" )' onmouseover='update( \"wizText\", \"Finish\" )' onmouseout='update( \"wizText\", \"&nbsp;\" )'>" )
         request.write( "</p><p align='center'><span id='wizText'></span></p></td></tr></table>" )
         request.write( "</td></tr></table>" )
         
@@ -49,14 +54,17 @@ class Wizard( HTMLBase ):
        pass
         
     def op_prev( self, request ):
+       pass
+        
+    def op_finish( self, request ):
        pass  
         
 class Sheet( HTMLBase ):
 
-    def __init__( self, urlWriter, feilds, title, location ):
+    def __init__( self, urlWriter, title, location ):
         HTMLBase.__init__( self )
         self.urlWriter = urlWriter
-        self.feilds = feilds
+        self.feilds = []
         self.title = title
         self.location = location
         self.passback = "()"
@@ -71,9 +79,9 @@ class Sheet( HTMLBase ):
         if temp_passback is not None and len( temp_passback ) > 0:
             temp_passback = temp_passback[ len( temp_passback )-1 ]
         else:
-            temp_passback = "(passback )"        
+            temp_passback = "( )"        
         
-        last_passback = ssxp2hash( string2sxp( temp_passback ) )
+        last_passback = ssxp2hash( string2sxp( temp_passback ) ) #use special function - will work with no head on sxp
         
         if DEBUG: print last_passback
         
@@ -90,22 +98,76 @@ class Sheet( HTMLBase ):
         
         if DEBUG: print self.passback
         
-        return last_passback #return the hash
-        
     def write_BODY( self, request ):
         
        request.write( "<p>%s</p>" % self.title )
     
-       previous_values = self.parseForm( request ) #get the hash for quick reference
+       previous_values = sxp2hash( string2sxp( self.passback ) ) #get the hash for quick reference
         
-       for (feild, name) in self.feilds:
-            value = previous_values.get( feild )
-            if value is None:
-               value = ''
-            request.write( "<p>%s<input type='text' name='%s' value='%s'></p>" % (name, feild, value) )
+        request.write( "<table width='100%' cellpadding='0' cellspacing='1' border='0'>" )
         
+       for (feild, control) in self.feilds:
+            control.write_Control( request, previous_values.get( feild ) )
+            
+        request.write( "</table>" )
+            
         request.write( "<input type='hidden' name='passback' value=\"%s\"></p>" % self.passback )
-        request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )        
+        request.write( "<input type='hidden' name='sheet' value='%s'></p>" % self.location )
+        
+    def addControl( self, control ):
+       self.feilds.append( [ control.getName(), control ] )
+        
+class SheetControl( HTMLBase ):
+
+    def __init__( self ):
+        HTMLBase.__init__( self )
+        self.name = ""
+        
+    def write_Control( self, request, persistedValue ):
+        request.write( "<tr colspan='2'><td>%s</td></tr>" % persistedValue )
+        
+    def validate( self ):
+       return True
+        
+    def getName( self ):
+       return self.name
+        
+    def setName( self, name ):
+       self.name = name
+        
+class InputControl( SheetControl ):
+
+    def __init__( self, name, defaultValue, humanText):
+        SheetControl.__init__( self )
+        self.setName( name )
+        
+        self.defaultValue = defaultValue
+        self.humanText = humanText
+        
+    def write_Control( self, request, persistedValue ):
+       if persistedValue is None:
+            persistedValue = self.defaultValue
+        
+        request.write( "<tr><td width='50%%'><p>%s</p></td><td width='50%%'><input type='text' name='%s' value=\"%s\"></td></tr>" % (self.humanText, self.getName(), persistedValue) )
+
+class TextControl( SheetControl ):
+
+    def __init__( self, text ):
+       SheetControl.__init__( self )
+        self.text = text
+        
+    def write_Control( self, request, persistedValue ):
+       request.write( "<tr><td colspan='2'><p>%s</p></td></tr>" % self.text )
+
+class SmallTextControl( SheetControl ):
+
+    def __init__( self, text ):
+       SheetControl.__init__( self )
+        self.text = text
+        
+    def write_Control( self, request, persistedValue ):
+       request.write( "<tr><td colspan='2'><p class='small'>%s</p></tr></td>" % self.text )
+        
                  
             
     
index c14137609f64a4ee4fb83cf0f2008ab53aa34dcf..b332b604823a44282b54170eef5d9e0ff37c66e9 100755 (executable)
@@ -13,10 +13,11 @@ def sxp2hash( s ):
     sxphash = {}
         
     for child in sxp.children( s ):
-       if child is types.ListType:
-            sxphash[ child[0] ] = sxp2hash( child[1] )
-        else:
-            sxphash[ child[0] ] = child[1]
+       if isinstance( child, types.ListType ) and len( child ) > 1:
+            if isinstance( child[1], types.ListType ) and len( child ) > 1:
+                sxphash[ child[0] ] = sxp2hash( child[1] )
+            else:
+                sxphash[ child[0] ] = child[1]
         
     return sxphash  
     
index b8f2a7a116823af65e70ad494e0b5027b3313b34..c7bd3d5880995809b086fea54fd745f61db13e31 100755 (executable)
@@ -36,7 +36,8 @@ install:
         
        install -m0644 images/next.png $(sv_insdir)/images
        install -m0644 images/previous.png $(sv_insdir)/images        
-
+       install -m0644 images/finish.png $(sv_insdir)/images 
+        
        # make include folder
        mkdir -p $(sv_insdir)/inc
        
diff --git a/tools/sv/images/finish.png b/tools/sv/images/finish.png
new file mode 100644 (file)
index 0000000..6c5d18a
Binary files /dev/null and b/tools/sv/images/finish.png differ